package com.dwcode.macro.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket docket(Environment environment){
        boolean profiles = environment.acceptsProfiles(Profiles.of("default"));

        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("杨栋文的小组")//分组名字
                .enable(profiles)// 是否开启swagger
                .apiInfo(apiInfo()) // API 信息
                .select() //启动对API的选择建设者
                .apis(RequestHandlerSelectors.basePackage("com.dwcode.macro")) //配置要扫描的接口
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfo("万家乐项目","","1.0","/index",
                new Contact("杨栋文","https://gitee.com/yangdongwen/macro_code","2280994932@qq.com"),"apache2.0 license",
                "/*", new ArrayList<>());
    }
}
